/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfbmonitor.task;

import java.sql.SQLException;
import java.util.List;
import java.util.TimerTask;

import org.jfbmonitor.beans.Attachment;
import org.jfbmonitor.beans.DataBase;
import org.jfbmonitor.beans.Transaction;
import org.jfbmonitor.beans.Statement;
import org.jfbmonitor.dao.AttachmentDao;
import org.jfbmonitor.dao.DataBaseDao;
import org.jfbmonitor.dao.StatementDao;
import org.jfbmonitor.dao.TransactionDao;
import org.jfbmonitor.view.Monitor;
import org.jfbmonitor.view.attachment.AttachmentTableModel;
import org.jfbmonitor.view.database.DataBaseTableModel;
import org.jfbmonitor.view.statement.StatementTableModel;
import org.jfbmonitor.view.transaction.TransactionTableModel;

/**
 *
 * @author rande
 */
public class Task extends TimerTask {
	private Monitor monitor;


	public Task( Monitor monitor ){
		this.monitor = monitor;
	}

    @Override
    public void run() {
		AttachmentDao  daoA = new AttachmentDao();
		TransactionDao daoT = new TransactionDao();
        DataBaseDao    daoD = new DataBaseDao();
        StatementDao   daoS = new StatementDao();
		try {
			List<Attachment> listAttachment                     = daoA.getAll(monitor.getAttachmentCondition());
            List<Transaction> listTransaction                   = daoT.getAll(monitor.getTransactionCondition());
            List<DataBase> listDataBase                         = daoD.getAll();
            List<org.jfbmonitor.beans.Statement> listStatement  = daoS.getAll(monitor.getStatementCondition());

			this.monitor.setTransactionTableModel( new TransactionTableModel(listTransaction));
			this.monitor.setDataBaseTableModel(new DataBaseTableModel(listDataBase));
            this.monitor.setAttachmentTableModel(new AttachmentTableModel(listAttachment));
            this.monitor.setStatementTableModel(new StatementTableModel(listStatement));
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }

}
